package day01;

import org.junit.Test;
import sun.plugin2.gluegen.runtime.CPU;

import java.sql.SQLOutput;
import java.util.*;

public class Test2 {
    public static void main(String[] args) {

    }

   @Test
    public void m1(){
        //Collection
        Collection<String> c = new ArrayList<>();
        c.add("lgy");
        System.out.println(c.size());
        System.out.println(c.isEmpty());
        c.clear();
        c.add("10");
        System.out.println(c.contains("10"));
        c.remove("10");
    }

    @Test
    public void m2(){
        //Collection

        //addAll
        ArrayList<String> list = new ArrayList<>();
        Collections.addAll(list,"1","2","3");
        list.forEach(System.out::println);

        System.out.println(Collections.binarySearch(list, "1"));

        // reverse shuffle swap fill
    }


    @Test
    public void m3(){

        // 创建 ArrayList<Employee> 集合
        List<Employee> employees = new ArrayList<>();

        // 添加员工对象到集合
        employees.add(new Employee("张三", 4000));
        employees.add(new Employee("李四", 5000));
        employees.add(new Employee("王五", 4000));
        employees.add(new Employee("赵六", 6000));

        Collections.sort(employees,Comparator.comparing(Employee::getMoney).reversed()
                .thenComparing(Employee::getName));
        employees.forEach(System.out::println);


        Employee[] list = {
                new Employee("张三", 4000),
                new Employee("李四", 5000),
                new Employee("王五", 4000),
                new Employee("赵六", 6000)
        };

        Arrays.sort(list,Comparator.comparing(Employee::getMoney).reversed()
                .thenComparing(Employee::getName));

    }

    class Employee{
        private String name;
        private double money;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public double getMoney() {
            return money;
        }

        public void setMoney(double money) {
            this.money = money;
        }

        public Employee() {
        }

        public Employee(String name, double money) {
            this.name = name;
            this.money = money;
        }

        @Override
        public String toString() {
            return "Employee{" +
                    "name='" + name + '\'' +
                    ", money=" + money +
                    '}';
        }
    }

}
